package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {
    //根据分类id查询分类下数量
    @Select("select count(*) from sky_take_out.setmeal where setmeal.category_id = #{id}")
    Integer count(Integer id);

    //新增套餐
    @AutoFill(value = OperationType.INSERT)
    void save(Setmeal setmeal);

    // setmealPageQueryDTO
    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    //批量删除套餐
    void deleteBatch(List<Long> ids);



    //根据id查询套餐
    @Select("select s.*,c.name categoryName from setmeal s left join category c on s.category_id = c.id where s.id = #{id}")
    SetmealVO getById(Long id);

    //修改套餐基本信息
    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    //设置套餐状态
    @Update("update setmeal set status = #{status} where id = #{id}")
    void status(Integer status, Long id);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
